<?php

namespace push;

use app\common\model\Config as ConfigModel;

/**
 * Push推送
 */
class Push
{

    /**
     * Push推送
     * type [1:专家点评、2:课程购买下发通知、3:专家点评次数下发通知、4:上课提醒、5:其他类型的通知]
     * @return string
     */
    public static function send($param)
    {
        
        $curl = curl_init();

        //  url路径
        $url  = ConfigModel::where('name','push_url')->cache(true,300)->value('value');

        curl_setopt_array($curl, 
            [
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING  => "",
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT   => 30,
                CURLOPT_HTTP_VERSION  => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => "GET",
                CURLOPT_POSTFIELDS => $param,
                CURLOPT_HTTPHEADER => [
                    "content-type: application/json"
                ],
            ]
        );

        $response = curl_exec($curl);
        $err      = curl_error($curl);
        curl_close($curl);

        if ($err) {
            return ['code'=>0,'msg'=>$err];
        } else {
            return ['code'=>1,'msg'=>'success'];
        }   
    }

}
